// To parse this JSON data, do
//
//     final welcome = welcomeFromJson(jsonString);

// ignore_for_file: prefer_if_null_operators, prefer_null_aware_operators, constant_identifier_names

import 'dart:convert';
import 'dart:ui';

class AssessmentResponse {
  AssessmentResponse({
    this.status,
    this.message,
    this.result,
  });

  int? status;
  String? message;
  AssessmentResult? result;

  factory AssessmentResponse.fromRawJson(String str) =>
      AssessmentResponse.fromJson(json.decode(str));

  String toRawJson() => json.encode(toJson());

  factory AssessmentResponse.fromJson(Map<String, dynamic> json) =>
      AssessmentResponse(
        status: json["status"] == null ? null : json["status"],
        message: json["message"] == null ? null : json["message"],
        result: json["result"] == null
            ? null
            : AssessmentResult.fromJson(json["result"]),
      );

  Map<String, dynamic> toJson() => {
        "status": status == null ? null : status,
        "message": message == null ? null : message,
        "result": result == null ? null : result?.toJson(),
      };
}

class AssessmentResult {
  AssessmentResult({
    this.mode,
    this.questionGroupId,
    this.bookId,
    this.recordStatus,
    this.commitTime,
    this.progressStatus,
    this.list,
  });

  String? mode;
  String? questionGroupId;
  String? bookId;
  String? recordStatus;
  int? commitTime;
  String? progressStatus;
  List<QuestionPart>? list;

  factory AssessmentResult.fromRawJson(String str) =>
      AssessmentResult.fromJson(json.decode(str));

  String toRawJson() => json.encode(toJson());

  factory AssessmentResult.fromJson(Map<String, dynamic> json) =>
      AssessmentResult(
        bookId: json["bookId"] == null ? null : json["bookId"],
        mode: json["mode"] == null ? null : json["mode"],
        questionGroupId:
            json["questionGroupId"] == null ? null : json["questionGroupId"],
        recordStatus:
            json["recordStatus"] == null ? null : json["recordStatus"],
        commitTime: json["commitTime"] == null ? null : json["commitTime"],
        progressStatus:
            json["progressStatus"] == null ? null : json["progressStatus"],
        list: json["list"] == null
            ? null
            : List<QuestionPart>.from(
                json["list"].map((x) => QuestionPart.fromJson(x))),
      );

  // AssessmentResult.fromJson2(Map<String, dynamic> json) {
  //   mode = json['mode'];
  //   recordStatus = json['recordStatus'];
  //   commitTime = json['commitTime'];
  //   progressStatus = json['progressStatus'];
  //   if (json['list'] != null) {
  //     list = <ListElement>[];
  //     json['list'].forEach((v) {
  //       list!.add(new ListElement.fromJson(v));
  //     });
  //   }
  // }

  Map<String, dynamic> toJson() {
    return {
      "mode": mode == null ? null : mode,
      "bookId": bookId == null ? null : bookId,
      "questionGroupId": questionGroupId == null ? null : questionGroupId,
      "recordStatus": recordStatus == null ? null : recordStatus,
      "commitTime": commitTime == null ? null : commitTime,
      "progressStatus": progressStatus == null ? null : progressStatus,
      "list": list == null ? null : list?.map((v) => v.toJson()).toList(),
    };
  }
}

class QuestionPart {
  QuestionPart({
    this.questions,
    this.introduction,
    this.partType,
  });

  List<QuestionSection>? questions;
  String? introduction;
  String? partType;

  factory QuestionPart.fromRawJson(String str) =>
      QuestionPart.fromJson(json.decode(str));

  String toRawJson() => json.encode(toJson());

  factory QuestionPart.fromJson(Map<String, dynamic> json) => QuestionPart(
        questions: json["questions"] == null
            ? null
            : List<QuestionSection>.from(
                json["questions"].map((x) => QuestionSection.fromJson(x))),
        introduction:
            json["introduction"] == null ? null : json["introduction"],
        partType: json["partType"] == null ? null : json["partType"],
      );

  Map<String, dynamic> toJson() {
    return {
      "questions":
          questions == null ? null : questions?.map((x) => x.toJson()).toList(),
      "introduction": introduction == null ? null : introduction,
      "partType": partType == null ? null : partType,
    };
  }
}

class QuestionSection {
  QuestionSection({
    this.limitTime,
    this.question,
    this.id,
    this.content,
  });

  int? limitTime;
  List<QuestionItem>? question;
  String? id;
  QuestionContent? content;

  factory QuestionSection.fromRawJson(String str) =>
      QuestionSection.fromJson(json.decode(str));

  String toRawJson() => json.encode(toJson());

  factory QuestionSection.fromJson(Map<String, dynamic> json) =>
      QuestionSection(
        limitTime: json["limitTime"] == null ? null : json["limitTime"],
        question: json["question"] == null
            ? null
            : List<QuestionItem>.from(
                json["question"].map((x) => QuestionItem.fromJson(x))),
        id: json["id"] == null ? null : json["id"],
        content: json["content"] == null
            ? null
            : QuestionContent.fromJson(json["content"]),
      );

  Map<String, dynamic> toJson() => {
        "limitTime": limitTime == null ? null : limitTime,
        "question":
            question == null ? null : question?.map((x) => x.toJson()).toList(),
        "id": id == null ? null : id,
        "content": content == null ? null : content?.toJson(),
      };
}

//
//for backup
// class QuestionElement {
//   QuestionElement({
//     this.answerCount,
//     this.bodyMajor,
//     this.bodyMinor,
//     this.head,
//     this.limitTime,
//     this.number,
//     this.point,
//     this.prepareTime,
//     this.reference,
//     this.skillPoint,
//     this.skill,
//     this.answer,
//     this.solution,
//     this.type,
//     this.body,
//     this.intelligenceScore
//   });

//   int? answerCount;
//   List<Content>? bodyMajor;
//   List<Content>? bodyMinor;
//   List<List<Content>>? body;
//   Content? head;
//   int? limitTime;
//   int? number;
//   int? point;
//   int? prepareTime;
//   Content? reference;
//   int? skillPoint;
//   Map? skill;
//   List<String>? answer;
//   List<String>? solution;
//   String? type;
//   int? intelligenceScore;

//   factory QuestionElement.fromJson(Map<String, dynamic> json) =>
//       QuestionElement(
//         answerCount: json["answerCount"],
//         bodyMajor: json["bodyMajor"] != null
//             ? List<Content>.from(
//                 json["bodyMajor"].map((x) => Content.fromJson(x)))
//             : null,
//         bodyMinor: json["bodyMinor"] != null
//             ? List<Content>.from(
//                 json["bodyMinor"].map((x) => Content.fromJson(x)))
//             : null,
//         body:json["body"]!=null ? List<List<Content>>.from(json["body"].map((x) => List<Content>.from(x.map((x) => Content.fromJson(x))))) : null,
//         head: json["head"]!=null ? Content.fromJson(json["head"]): null,
//         limitTime: json["limitTime"],
//         number: json["number"],
//         point: json["point"],
//         prepareTime: json["prepareTime"],
//         reference:json["reference"]!=null ?  Content.fromJson(json["reference"]): null,
//         skillPoint: json["skillPoint"],
//         skill: json["skill"],
//         solution: json["solution"] != null
//             ? List<String>.from(json["solution"].map((x) => x))
//             : null,
//         answer: json["answer"] != null
//             ? List<String>.from(json["answer"].map((x) => x))
//             : null,
//         type: json["type"],
//         intelligenceScore: json["intelligenceScore"],
//       );

//   Map<String, dynamic> toJson() => {
//         "answerCount": answerCount,
//         "bodyMajor": List<dynamic>.from(bodyMajor!.map((x) => x.toJson())),
//         "bodyMinor": List<dynamic>.from(bodyMinor!.map((x) => x.toJson())),
//        "body": List<dynamic>.from(body!.map((x) => List<dynamic>.from(x.map((x) => x.toJson())))),
//         "head": head != null ? head?.toJson() : null,
//         "skill": skill,
//         "limitTime": limitTime,
//         "number": number,
//         "point": point,
//         "prepareTime": prepareTime,
//         "reference": reference != null ? reference!.toJson() : null,
//         "skillPoint": skillPoint,
//         "solution": solution != null
//             ? List<dynamic>.from(solution!.map((x) => x))
//             : null,
//         "answer":
//             answer != null ? List<dynamic>.from(answer!.map((x) => x)) : null,
//         "type": type,
//        "intelligenceScore": intelligenceScore,
//       };
// }

class QuestionItem {
  QuestionItem(
      {this.head,
      this.limitTime,
      this.reference,
      this.number,
      this.answerCount,
      this.answer,
      this.solution,
      this.type,
      this.body,
      this.prepareTime,
      this.intelligenceScore,
      this.isExpanded = false,
      this.totalScore,
      this.score,
      this.skill,
      this.skillPoint,
      this.comment,
      this.fileId});

  QuestionContent? head;
  int? limitTime;
  QuestionContent? reference;
  int? number;
  int? answerCount;
  List<String>? answer;
  List<String>? solution;
  String? type;
  List<List<QuestionContent>>? body;
  int? prepareTime;
  int? intelligenceScore;
  bool isExpanded;
  int? totalScore;
  int? score;
  int? skillPoint;
  Map? skill;
  String? comment;
  String? fileId;

  factory QuestionItem.fromRawJson(String str) =>
      QuestionItem.fromJson(json.decode(str));

  String toRawJson() => json.encode(toJson());

  factory QuestionItem.fromJson(Map<String, dynamic> json) => QuestionItem(
        head: json["head"] == null
            ? null
            : QuestionContent.fromJson(json["head"]),
        limitTime: json["limitTime"] == null ? null : json["limitTime"],
        reference: json["reference"] == null
            ? null
            : QuestionContent.fromJson(json["reference"]),
        number: json["number"] == null ? null : json["number"],
        answerCount: json["answerCount"] == null ? null : json["answerCount"],
        answer: json["answer"] == null
            ? null
            : List<String>.from(json["answer"].map((x) => x ?? "")),
        solution: json["solution"] == null
            ? null
            : List<String>.from(json["solution"].map((x) => x)),
        type: json["type"] == null ? null : json["type"],
        body: json["body"] == null
            ? null
            : List<List<QuestionContent>>.from(json["body"].map((x) =>
                List<QuestionContent>.from(
                    x.map((x) => QuestionContent.fromJson(x))))),
        prepareTime: json["prepareTime"] == null ? null : json["prepareTime"],
        intelligenceScore: json["intelligenceScore"],
        isExpanded: false,
        skillPoint: json["skillPoint"],
        skill: json["skill"],
      );

  Map<String, dynamic>? toJson() => {
        "head": head == null ? null : head?.toJson(),
        "limitTime": limitTime == null ? null : limitTime,
        "reference": reference == null ? null : reference?.toJson(),
        "number": number == null ? null : number,
        "answerCount": answerCount == null ? null : answerCount,
        "answer":
            answer == null ? null : List<dynamic>.from(answer!.map((x) => x)),
        "solution": solution == null
            ? null
            : List<dynamic>.from(solution!.map((x) => x)),
        "type": type == null ? null : type,
        "body": body == null
            ? null
            : body?.map((x) => x.map((x) => x.toJson()).toList()).toList(),
        "prepareTime": prepareTime == null ? null : prepareTime,
        "intelligenceScore": intelligenceScore,
        "skill": skill,
        "skillPoint": skillPoint,
      };

  static const String QUESTION_TYPE_OPTION = "option";
  static const String QUESTION_TYPE_SPEAK = "speak";
  static const String QUESTION_TYPE_WRITE = "write";
  static const String QUESTION_TYPE_JUDGE = "judge";
  static const String QUESTION_TYPE_SPEECH = "speech";
  static const String QUESTION_TYPE_MATCH = "match";
  static const String QUESTION_TYPE_SORT = "sort";
  static const String QUESTION_TYPE_GROUP = "group";
  static const String QUESTION_TYPE_INPUT = "input";
  static const String QUESTION_TYPE_FILL = "fill";
  static const String QUESTION_TYPE_TABLE = "table";
}

class QuestionContentPlus {
  QuestionContentPlus(
      {this.baseValue,
      this.show,
      this.text,
      this.image,
      this.audio,
      this.color,
      this.isVisible,
      this.shakeColor,
      this.itemRect});

  String? baseValue;
  String? show;
  String? text;
  String? image;
  String? audio;
  Color? color;
  bool? isVisible;
  int? shakeColor;
  Rect? itemRect;
}

class QuestionContent {
  QuestionContent(
      {this.baseValue,
      this.innerText,
      this.item,
      this.show,
      this.text,
      this.audio,
      this.image,
      this.pdf,
      this.questionTitleNum,
      this.json});

  String? baseValue;
  String? innerText;
  List<Item>? item;
  String? show;
  String? text;
  String? audio;
  String? image;
  String? pdf;
  String? questionTitleNum;
  String? json;

  factory QuestionContent.fromJson(Map<String, dynamic> json) =>
      QuestionContent(
          baseValue: json["baseValue"],
          innerText: json["innerText"],
          item: json["item"] != null
              ? List<Item>.from(json["item"].map((x) => Item.fromJson(x)))
              : null,
          show: json["show"],
          text: json["text"],
          audio: json["audio"],
          image: json["image"],
          pdf: json["pdf"],
          questionTitleNum:'',
          json: json["json"]);

  Map<String, dynamic> toJson() => {
        "baseValue": baseValue,
        "innerText": innerText,
        "item": item != null
            ? List<dynamic>.from(item!.map((x) => x.toJson()))
            : null,
        "show": show,
        "text": text,
        "audio": audio,
        "image": image,
        "pdf": pdf,
        "json": json
      };
  static const String QUESTION_SHOW_TYPE_TEXT = "text";
  static const String QUESTION_SHOW_TYPE_IMAGE = "image";
  static const String QUESTION_SHOW_TYPE_AUDIO = "audio";
}

class Item {
  Item({
    this.setting,
    this.type,
    this.value,
  });

  String? setting;
  String? type;
  String? value;

  factory Item.fromJson(Map<String, dynamic> json) => Item(
        setting: json["setting"],
        type: json["type"],
        value: json["value"],
      );

  Map<String, dynamic> toJson() => {
        "setting": setting,
        "type": type,
        "value": value,
      };
}

class ArticleWord {
  ArticleWord({this.key, this.value, this.status, this.behavior});

  String? key;
  String? value;
  String? status;
  String? behavior;
  factory ArticleWord.fromJson(Map<String, dynamic> json) =>
      ArticleWord(key: json["key"], value: json["value"], status: '', behavior: '');

  Map<String, dynamic> toJson() => {"key": key, "value": value};
}
